﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ASS.BUS.DTO;
using ASS.BUS.Services;
using ASS.DAO;

namespace ASS
{
    public partial class FrmInsertPatient : Form
    {
        FrmMainClinicStaff frmMain;
        public FrmInsertPatient()
        {
            InitializeComponent();
        }
        
        public FrmInsertPatient(FrmMainClinicStaff FrmMain)
        {
            frmMain = FrmMain;
            InitializeComponent();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }


        private void FrmInsertPatient_Load(object sender, EventArgs e)
        {
            date.Value = DateTime.Now.Date;

            var yearStrings = new string[90];
            var beginYear = DateTime.Now.Year - 100;

            for (var i = 0; i < 90; ++i)
            {
                yearStrings[i] = beginYear.ToString();
                beginYear++;
            }
            cboBirthday.DataSource = yearStrings;

            string[] genderStrings = {"Nam", "Nữ"};
            cboGender.DataSource = genderStrings;

            
        }

        private void btnInsert_Click_1(object sender, EventArgs e)
        {
            var benhNhanServices = new BenhNhanServices();
            var benhNhan = new BenhNhan();
            var thanNhan = new ThanNhanBenhNhan();
            var thanNhanServices = new ThanNhanServices();

            benhNhan.Ten = txtNamePatient.Text;
            benhNhan.DiaChi = txtAddress.Text;

            if (cboBirthday.SelectedIndex != -1)
            {
                benhNhan.NgaySinh = cboBirthday.SelectedValue.ToString();
            }

            if (cboGender.SelectedIndex != -1)
            {
                benhNhan.GioiTinh = cboGender.SelectedValue.ToString();
            }

            var addSuccess = benhNhanServices.Add(benhNhan);
            //thanNhan.Ten = txtNameRelative.Text;
            //thanNhan.SoDienThoai = txtPhoneNumber.Text;
            //thanNhan.BenhNhan.MaBn = benhNhan.MaBn;
            //bool addThanNhan = thanNhanServices.Add(thanNhan);
            MessageBox.Show((addSuccess /*&& addThanNhan*/) ? "Thêm Thành công" : "Thêm thất bại", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (addSuccess)
            {
                frmMain.dvgPatient.DataSource = benhNhanServices.GetBenhNhans();
                //this.Close();
            }


        }
    }
}
